/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package qltv;

import Controller.ChiTietPhieuMuonController;
import Controller.DocGiaController;
import Controller.NgonNguController;
import Controller.NhaXuatBanController;
import Controller.PhieuMuonController;
import Controller.SachController;
import Controller.TacGiaController;
import Controller.TheLoaiController;
import Controller.tmpTaoPhieuMuonController;
import DataAccess.ChiTietPhieuMuon;
import DataAccess.DocGia;
import DataAccess.NgonNgu;
import DataAccess.NguoiDung;
import DataAccess.NhaXuatBan;
import DataAccess.PhieuMuon;
import DataAccess.Sach;
import DataAccess.TacGia;
import DataAccess.TheLoai;
import DataAccess.TmpTaoPhieuMuon;
//import com.sun.jndi.ldap.Connection;
import java.io.InputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;
import net.sf.jasperreports.engine.JasperCompileManager;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.engine.JasperReport;
import net.sf.jasperreports.view.JasperViewer;

/**
 *
 * @author My PC
 */
interface IMuonSach
{
    void Register(IKiemTra kt);
    void Remove(IKiemTra kt);
    void Notify(ChiTietPhieuMuon ctpm,Date ngayhentra);
}
interface IKiemTra
{
    void Update(ChiTietPhieuMuon ctpm,Date ngayhentra);
}
public class MuonSachform extends javax.swing.JFrame{

    /**
     * Creates new form MuonSachform
     */
    
    
    PhieuMuonController objControl=new PhieuMuonController();
    ChiTietPhieuMuonController ctpmControl=new ChiTietPhieuMuonController();
    DocGiaController dgControl=new DocGiaController();
    TacGiaController tgControl=new TacGiaController();
    NhaXuatBanController nxbControl=new NhaXuatBanController();
    TheLoaiController tlControl=new TheLoaiController();
    NgonNguController nnControl=new NgonNguController();
    List<ChiTietPhieuMuon> lstCT=null;
    
    int chon,lastID;
    Date d;
    Date t;
    public MuonSachform() {
        initComponents();
        
        lastID=objControl.GetLastID()+1;
        txtPhieuMuonID.setText(String.valueOf(lastID));
         d =Calendar.getInstance().getTime();//new Date(System.currentTimeMillis());
         t=addDays(d,182);
        String s=d.toString();
        txtNgayMuon.setText(s);
        txtNgayHenTra.setText(String.valueOf(t));
    }
    public static Date addDays(Date d, int days)
    {
        d.setTime(d.getTime() + days * 1000 * 60 * 60 * 24);
        return d;
    }
    
    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        txtPhieuMuonID = new javax.swing.JTextField();
        txtNgayMuon = new javax.swing.JTextField();
        txtNgayHenTra = new javax.swing.JTextField();
        jPanel2 = new javax.swing.JPanel();
        jLabel4 = new javax.swing.JLabel();
        txtDocGiaID = new javax.swing.JTextField();
        lbChucDanh = new javax.swing.JLabel();
        jButton1 = new javax.swing.JButton();
        lbTenDocGia1 = new javax.swing.JLabel();
        lbDonVi = new javax.swing.JLabel();
        lbEmail = new javax.swing.JLabel();
        lbNgayHetHan = new javax.swing.JLabel();
        lbNgayLamThe1 = new javax.swing.JLabel();
        jPanel3 = new javax.swing.JPanel();
        jLabel5 = new javax.swing.JLabel();
        txtTaiLieuID = new javax.swing.JTextField();
        btnKiemTraSach = new javax.swing.JButton();
        lbTenTaiLieu = new javax.swing.JLabel();
        lbTenTacGia = new javax.swing.JLabel();
        lbTheLoai = new javax.swing.JLabel();
        lbNgonNgu = new javax.swing.JLabel();
        lbSoLuong = new javax.swing.JLabel();
        lbTenNhaXuatBan = new javax.swing.JLabel();
        labTenTL = new javax.swing.JLabel();
        labNXB = new javax.swing.JLabel();
        labTacGia = new javax.swing.JLabel();
        labNN = new javax.swing.JLabel();
        labSL = new javax.swing.JLabel();
        labTheLoai = new javax.swing.JLabel();
        jPanel4 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();
        jLabel6 = new javax.swing.JLabel();
        btnMuon = new javax.swing.JButton();
        btnChon = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Thông tin phiếu mượn"));

        jLabel1.setText("Mã phiếu mượn : ");

        jLabel2.setText("Ngày mượn : ");

        jLabel3.setText("Ngày hẹn trả : ");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, 93, Short.MAX_VALUE)
                            .addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(txtPhieuMuonID, javax.swing.GroupLayout.DEFAULT_SIZE, 263, Short.MAX_VALUE)
                            .addComponent(txtNgayMuon, javax.swing.GroupLayout.Alignment.TRAILING)))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 93, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(txtNgayHenTra)))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(33, 33, 33)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(txtPhieuMuonID, javax.swing.GroupLayout.DEFAULT_SIZE, 29, Short.MAX_VALUE))
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(11, 11, 11)
                        .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(18, 18, 18)
                        .addComponent(txtNgayMuon, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtNgayHenTra, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(126, Short.MAX_VALUE))
        );

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Thông tin độc giả"));

        jLabel4.setText("Mã thẻ thư viện :");

        lbChucDanh.setText("Chức danh :   ");

        jButton1.setText("Kiểm tra");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        lbTenDocGia1.setText("Tên độc giả :   ");

        lbDonVi.setText("Đơn vị :   ");

        lbEmail.setText("Email : ");

        lbNgayHetHan.setText("Ngày hết hạn : ");

        lbNgayLamThe1.setText("Ngày làm thẻ :  ");

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGap(19, 19, 19)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(lbNgayHetHan, javax.swing.GroupLayout.PREFERRED_SIZE, 376, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 94, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(txtDocGiaID, javax.swing.GroupLayout.PREFERRED_SIZE, 164, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(44, 44, 44)
                        .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 104, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                        .addComponent(lbDonVi, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(lbTenDocGia1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 376, Short.MAX_VALUE)
                        .addComponent(lbChucDanh, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addComponent(lbEmail, javax.swing.GroupLayout.PREFERRED_SIZE, 376, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lbNgayLamThe1, javax.swing.GroupLayout.PREFERRED_SIZE, 376, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(89, Short.MAX_VALUE))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap(15, Short.MAX_VALUE)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtDocGiaID, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 55, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(lbTenDocGia1, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(lbChucDanh, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(lbDonVi, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(lbEmail, javax.swing.GroupLayout.PREFERRED_SIZE, 27, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(lbNgayLamThe1, javax.swing.GroupLayout.PREFERRED_SIZE, 27, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(lbNgayHetHan, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder("Thông tin tài liệu"));
        jPanel3.setEnabled(false);

        jLabel5.setText("Mã tài liệu : ");

        txtTaiLieuID.setEnabled(false);

        btnKiemTraSach.setText("Kiểm tra");
        btnKiemTraSach.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnKiemTraSachActionPerformed(evt);
            }
        });

        lbTenTaiLieu.setText("Tên Tài Liệu : ");

        lbTenTacGia.setText("Tác Giả : ");

        lbTheLoai.setText("Thể loại : ");

        lbNgonNgu.setText("Ngôn ngữ : ");

        lbSoLuong.setText("Số lượng : ");

        lbTenNhaXuatBan.setText("Nhà xuất bản : ");

        labTenTL.setText("jLabel7");

        labNXB.setText("jLabel8");

        labTacGia.setText("jLabel8");

        labNN.setText("jLabel8");

        labSL.setText("jLabel8");

        labTheLoai.setText("jLabel8");

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addComponent(jLabel5)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(txtTaiLieuID, javax.swing.GroupLayout.PREFERRED_SIZE, 141, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(26, 26, 26)
                        .addComponent(btnKiemTraSach))
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addComponent(lbTenTaiLieu)
                        .addGap(18, 18, 18)
                        .addComponent(labTenTL, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addComponent(lbTenTacGia, javax.swing.GroupLayout.PREFERRED_SIZE, 67, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(labTacGia, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(lbTenNhaXuatBan)
                            .addComponent(lbTheLoai)
                            .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                .addComponent(lbSoLuong, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(lbNgonNgu, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(labNN, javax.swing.GroupLayout.PREFERRED_SIZE, 215, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(labNXB, javax.swing.GroupLayout.PREFERRED_SIZE, 215, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(labSL, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(labTheLoai, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtTaiLieuID)
                    .addComponent(btnKiemTraSach))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lbTenTaiLieu, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(labTenTL, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lbTenTacGia, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(labTacGia, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lbTenNhaXuatBan, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(labNXB, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lbTheLoai, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(labTheLoai, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lbNgonNgu, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(labNN, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lbSoLuong, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(labSL, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)))
        );

        jPanel4.setBorder(javax.swing.BorderFactory.createTitledBorder("Danh sách tài liệu"));

        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Mã tài liệu", "Tên tài liệu", "Tình trạng"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.Integer.class, java.lang.String.class, java.lang.String.class
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }
        });
        jScrollPane1.setViewportView(jTable1);

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 533, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 2, Short.MAX_VALUE))
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 302, Short.MAX_VALUE)
        );

        jLabel6.setFont(new java.awt.Font("Tahoma", 0, 36)); // NOI18N
        jLabel6.setText("MƯỢN SÁCH");

        btnMuon.setText("Mượn tài liệu");
        btnMuon.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnMuonActionPerformed(evt);
            }
        });

        btnChon.setText("Chọn tài liệu");
        btnChon.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnChonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addGap(18, 18, 18))
                            .addGroup(layout.createSequentialGroup()
                                .addContainerGap()
                                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 18, Short.MAX_VALUE))
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(btnChon, javax.swing.GroupLayout.PREFERRED_SIZE, 109, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(38, 38, 38)
                                .addComponent(btnMuon, javax.swing.GroupLayout.PREFERRED_SIZE, 112, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(95, 95, 95)))
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(375, 375, 375)
                        .addComponent(jLabel6, javax.swing.GroupLayout.PREFERRED_SIZE, 212, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(0, 0, Short.MAX_VALUE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel6, javax.swing.GroupLayout.PREFERRED_SIZE, 55, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(btnMuon, javax.swing.GroupLayout.PREFERRED_SIZE, 44, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(btnChon, javax.swing.GroupLayout.PREFERRED_SIZE, 44, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents
DocGia dg;
    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        // TODO add your handling code here:
        try{
            dg=dgControl.GetObjByID(Integer.parseInt(txtDocGiaID.getText()),"DocGia");
        lbTenDocGia1.setText(lbTenDocGia1.getText()+dg.getTenDocGia() );
        lbChucDanh.setText(lbChucDanh.getText()+dg.getNgheNghiep());
        lbDonVi.setText(lbDonVi.getText()+dg.getDonVi());
        lbEmail.setText(lbEmail.getText()+dg.getEmail());
        lstCT=ctpmControl.GetCTPMByDocGia(dg.getDocGiaId());
        int i=0;
        for(Object o:lstCT)
        {
            ChiTietPhieuMuon ctpm=(ChiTietPhieuMuon)o;
            List<PhieuMuon> lstPM=null;
            PhieuMuon pm= objControl.GetObjByID(ctpm.getPhieuMuonId(), "PhieuMuon");
            if(pm.getNgayHenTra().before(new Date(System.currentTimeMillis())))
                i++;
        }
        KiemTraform ktForm=new KiemTraform(dg,lstCT);
        if(lstCT.size()==8 || i>0)
        {
        int click=JOptionPane.showConfirmDialog(null, " Bạn không thể mượn thêm tài liệu. Bạn có muốn kiểm tra chi tiết không ?","Kiểm tra",JOptionPane.YES_NO_OPTION);
        if(click==JOptionPane.YES_OPTION)
            ktForm.show();
         }
        else 
        {
        int click=JOptionPane.showConfirmDialog(null, " Bạn có thể mượn thêm tài liệu. Bạn có muốn kiểm tra chi tiết không ?","Kiểm tra",JOptionPane.YES_NO_OPTION);
        txtTaiLieuID.setEditable(true);
        if(click==JOptionPane.YES_OPTION)
            ktForm.show();    
        }
        
        }
        catch(Exception ex)
        {
            JOptionPane.showConfirmDialog(null, " Khong co ma doc gia nay","Thông báo",JOptionPane.OK_OPTION);
        }
    }//GEN-LAST:event_jButton1ActionPerformed
    SachController sachControl=new SachController();
    Sach s;
    private void btnKiemTraSachActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnKiemTraSachActionPerformed
        // TODO add your handling code here:
        try{
        s=sachControl.GetObjByID(Integer.parseInt(txtTaiLieuID.getText()), "Sach");
        labTenTL.setText(s.getTenSach());
        TacGia tg=tgControl.GetObjByID(s.getTacGiaId(), "TacGia");
        labTacGia.setText(tg.getTenTacGia());
        TheLoai tl=tlControl.GetObjByID(s.getTheLoaiId(), "TheLoai");
        labTheLoai.setText(tl.getTenTheLoai());
        NhaXuatBan nxb=nxbControl.GetObjByID(s.getNhaXuatBanId(), "NhaXuatBan");
        labNXB.setText(nxb.getTenNhaXuatBan());
        NgonNgu nn=nnControl.GetObjByID(s.getNgonNguId(), "NgonNgu");
        labNN.setText(nn.getTenNgonNgu());
        labSL.setText(String.valueOf(s.getSoSach()));
        }catch(Exception e)
        {
            JOptionPane.showConfirmDialog(null, " Không có mã tài liệu này","Thông báo",JOptionPane.OK_OPTION);
        }
        
    }//GEN-LAST:event_btnKiemTraSachActionPerformed
DefaultTableModel model;// = (DefaultTableModel) jTable1.getModel();
    private void btnChonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnChonActionPerformed
        // TODO add your handling code here:
        if(ctpmControl.KiemTraTaiLieu(s))
        {
            if(ctpmControl.KiemTraSoLuong(dg.getDocGiaId(), jTable1, s.getSachId()))
            {
                model = (DefaultTableModel) jTable1.getModel();
                model.addRow(new Object[]{s.getSachId(), s.getTenSach(), "bình thường"});
            }
        }
    }//GEN-LAST:event_btnChonActionPerformed
tmpTaoPhieuMuonController tpmControl=new tmpTaoPhieuMuonController();
    private void btnMuonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnMuonActionPerformed
        // TODO add your handling code here:
        tpmControl.DeleteAll("TmpTaoPhieuMuon");
        PhieuMuon phieumuon=new PhieuMuon();
        int pmID=Integer.parseInt(txtPhieuMuonID.getText());
        phieumuon.setPhieuMuonId(pmID);
        int dgID=Integer.parseInt(txtDocGiaID.getText());
        phieumuon.setDocGiaId(dgID);
        phieumuon.setNgayMuon(Calendar.getInstance().getTime());
        phieumuon.setNgayHenTra(t);
        objControl.Insert(phieumuon);
        
        
        for(int i=0;i<model.getColumnCount()-2;i++)
        {
            ChiTietPhieuMuon ctpm=new ChiTietPhieuMuon();
            ctpm.setCtpmid(ctpmControl.GetLastID()+1);
            ctpm.setPhieuMuonId(Integer.parseInt(txtPhieuMuonID.getText()));
            ctpm.setSachId(Integer.parseInt(model.getValueAt(i, 0).toString()));
            ctpm.setTinhTrangSach("tốt");
            ctpmControl.Insert(ctpm);
            TmpTaoPhieuMuon tmp=new TmpTaoPhieuMuon();
            
            Sach s=sachControl.GetObjByID(ctpm.getSachId(), "Sach");
            sachControl.UpdateSoLuong(ctpm.getSachId(), s.getSoSach()-1);
            
            tmp.setDocGiaId(dgID);
            tmp.setPhieuMuonId(pmID);
            tmp.setNgayMuon(d);
            tmp.setNgayHenTra(phieumuon.getNgayHenTra());
            tmp.setSachId(ctpm.getSachId());
            tmp.setTenDocGia(dgControl.GetObjByID(phieumuon.getDocGiaId(), "DocGia").getTenDocGia());
            tmp.setTenSach(sachControl.GetObjByID(ctpm.getSachId(), "Sach").getTenSach());
            tmp.setTinhTrangSach("bình thường");
            tpmControl.Insert(tmp);
        }
            //InP
            int click=JOptionPane.showConfirmDialog(null, " Bạn có muốn in phiếu mượn không ?","Thông báo",JOptionPane.YES_NO_OPTION);
        if(click==JOptionPane.YES_OPTION)
        {
            try { 
            String reportName = "E:\\hoctap\\ky 8\\Java\\QLTV\\src\\report\\InPhieuMuon.jrxml"; 
            Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
            String database="jdbc:sqlserver://MyPC:1433;databaseName=QLTV";
            String us="sa";
            String pass="sa";
            Connection conn=(Connection)DriverManager.getConnection(database,us,pass);
            HashMap map = new HashMap(); 
            InputStream is = this.getClass().getClassLoader().getResourceAsStream(reportName); 
            JasperReport jr=JasperCompileManager.compileReport(reportName);
            JasperPrint jasperPrint = JasperFillManager.fillReport(jr, map, conn); 
            //     JasperExportManager.exportReportToHtmlFile(jasperPrint, "huy.html"); 

         //   JasperViewer jv = new JasperViewer(jasperPrint, false); 
            JasperViewer.viewReport(jasperPrint);
          //  jv.setVisible(true); 
        } catch (Exception ex) { 
            System.out.println(ex.getMessage()); 
        } 
        }  
    }//GEN-LAST:event_btnMuonActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(MuonSachform.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(MuonSachform.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(MuonSachform.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(MuonSachform.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new MuonSachform().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnChon;
    private javax.swing.JButton btnKiemTraSach;
    private javax.swing.JButton btnMuon;
    private javax.swing.JButton jButton1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable jTable1;
    private javax.swing.JLabel labNN;
    private javax.swing.JLabel labNXB;
    private javax.swing.JLabel labSL;
    private javax.swing.JLabel labTacGia;
    private javax.swing.JLabel labTenTL;
    private javax.swing.JLabel labTheLoai;
    private javax.swing.JLabel lbChucDanh;
    private javax.swing.JLabel lbDonVi;
    private javax.swing.JLabel lbEmail;
    private javax.swing.JLabel lbNgayHetHan;
    private javax.swing.JLabel lbNgayLamThe1;
    private javax.swing.JLabel lbNgonNgu;
    private javax.swing.JLabel lbSoLuong;
    private javax.swing.JLabel lbTenDocGia1;
    private javax.swing.JLabel lbTenNhaXuatBan;
    private javax.swing.JLabel lbTenTacGia;
    private javax.swing.JLabel lbTenTaiLieu;
    private javax.swing.JLabel lbTheLoai;
    private javax.swing.JTextField txtDocGiaID;
    private javax.swing.JTextField txtNgayHenTra;
    private javax.swing.JTextField txtNgayMuon;
    private javax.swing.JTextField txtPhieuMuonID;
    private javax.swing.JTextField txtTaiLieuID;
    // End of variables declaration//GEN-END:variables
}
